import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: Home,
    children: [
      {
        //用户列表
        path: 'users',
        component: () => import('../views/Users.vue')
      },
      {
        // 角色列表
        path: 'role-list',
        component: () => import('../views/RoleLists.vue')
      },
      {
        // 权限列表
        path: 'jurisdiction',
        component: () => import('../views/JurisdictionList.vue')
      },
      {
        // 商品列表
        path: 'things-lists',
        component: () => import('../views/ThingsLists.vue'),
        children: [
          {
            // 添加商品
            path: 'addThings',
            component: () => import('../views/AddThings.vue')
          }
        ]
      },

      {
        //商品分类
        path: 'thing-class',
        component: () => import('../views/ThingClass.vue')
      },
      {
        //分类参数
        path: 'class-paramater',
        component: () => import('../views/ClassParamater.vue')
      },
      {
        //订单列表
        path: 'order-lists',
        component: () => import('../views/OrderLists.vue')
      },
      {
        //数据报表
        path: 'report-form',
        component: () => import('../views/ReportForm.vue')
      },
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Loginin.vue')
  },

]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  const isToken = sessionStorage.getItem('token')
  // console.log(isToken);
  if (to.path !== '/login' && !isToken) next('/login')
  next()
})

export default router
